package com.gywm.bag;

import java.sql.SQLException;
import java.util.ArrayList;

import com.Wzs.lbtcp.lbtcp;
import com.wzsck.util.DBManager;
import com.wzsck.util.QueryDataResult;

public class GYWMManager {
//查询
	public ArrayList<gywm> query(){//把东西存到动态数组里面
		ArrayList<gywm> list = new ArrayList<gywm>();
		String sql = "select * from wzs_companyintroduction";//sql语句查表book里的东西
		QueryDataResult qdr =DBManager.executeQuery(sql);
		if (qdr.rs!=null){
			try {
				while (qdr.rs.next()){
					int id=qdr.rs.getInt("id");//编号,后面是获取book实体类里的id getInt（“id”）
					String time=qdr.rs.getString("time");//时间
					String imgurl=qdr.rs.getString("imgurl");//图片
					String description=qdr.rs.getString("description");//公司介绍					
					gywm x= new gywm(id,time,imgurl,description);
					list.add(x);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}
	
	//add
	public int add( String time,String imgurl, String description) {
		String sql = String.format(
				"insert into wzs_companyintroduction( `time`,  `imgurl` ,`description`) values('%s','%s','%s')",
				 time,  imgurl ,description);
		int i = DBManager.executeUpdate(sql);
		return i;

	}
	public int update(String id, String time,String imgurl, String description) {
		String sql = String.format(
				"update wzs_companyintroduction set `time`='%s',`imgurl`='%s',`description`='%s' , where id = %d",
				 time,  imgurl ,description,id);
		int i = DBManager.executeUpdate(sql);
		return i;
	}
	public int del(int id) {
		String sql = "delete from wzs_companyintroduction where id = " + id;
		int i = DBManager.executeUpdate(sql);
		return i;
	}
	
	//==========================================================
	 public int count() {//count查非空
	 		String sql="select count(*) from wzs_companyintroduction";//换表名
	 		QueryDataResult qdr=DBManager.executeQuery(sql);
	 		if (qdr.rs!=null) {
	 			try {
	 				while (qdr.rs.next()) {
	 					int count =qdr.rs.getInt("count(*)");
	 					return count;
	 				}
	 			} catch (SQLException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 			}
	 		}
	 		return 0;
	 	}
	 
	     public ArrayList<gywm> chaxun(int page,int limit) {
	 	    ArrayList<gywm> list =new ArrayList<gywm>();//limit返回行数 limit 开始数 , 行数
				String sql="select * from  wzs_companyintroduction  limit "+(page - 1)*limit+","+limit;//换表明
				QueryDataResult qdr=DBManager.executeQuery(sql);
				gywm x=null;
				if (qdr.rs!=null){
					try {
						while (qdr.rs.next()){
							int id=qdr.rs.getInt("id");//编号,后面是获取book实体类里的id getInt（“id”）
							String time=qdr.rs.getString("time");//时间
							String imgurl=qdr.rs.getString("imgurl");//图片
							String description=qdr.rs.getString("description");//公司介绍					
							 x= new gywm(id,time,imgurl,description);
							list.add(x);
						}
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				qdr.close();
				return list;		
		} 
}

